<!DOCTYPE html>
<html>
  <head>
    <title><%= username%> <%= title %></title>
    <!-- 静态资源路径相对于 public 就是public 是根目录 -->
    <!-- <link rel='stylesheet' href='/stylesheets/style.css' /> -->
   <link rel="stylesheet" href="/stylesheets/index.css">
    <link rel="stylesheet" href="/stylesheets/common.css">
    <script src="/javascripts/jquery-1.11.3.min.js"></script>
    <script src="/javascripts/header.js"></script>
  </head>
  <body>
     <%- include header %>
    <div class="main">
      <div class="index-left">
       
        <p class="wel">欢迎来到<%= username%> <%= title %></p>
        <div class="headerImg">
          <p class="img-head" style="height:100px; width:100px;border-radius:50%;background: rgb(219, 123, 123);overflow: hidden;line-height: 100px;text-align: center" >
            
                  <img src="<%= Imgurl%>" alt="头像">
          </p>
          <%if(username){%>
            <form method="POST" action="/profile" enctype="multipart/form-data" class="loadImg">
            
              <input type="file" name="avatar" >
                <input type="submit" value="上传头像">
            </form>
            <div class="distruct">
              <h2>博主介绍</h2>
              <p>一个努力学习前端的女程序猿</p>
            </div>
          <%} else{%>
            <p>请先登录</p>
          <%}%>
          
          
        </div>
   </div>

   <div class="index-right">
      <ul>
        <%for(var i=0;i < data.length; i++){ %>
          <li class="arc">
            <a href="/users/articles/post/<%= data[i]._id%>" class="arcHead" style="outline: none;">
              <h2 ><%= data[i].arctitle %></h2>
            </a>
            <div class="arcContent"><p ><%- data[i].content %></p></div>
            
          </li>
          
          <% } %>
          <div>
            <%if(pageNum-1< 1 ){%>
            <a href="#" class="style-btn">已是第一页</a>
            <%} else{%> 
              <a href="/?num=<%= pageNum-1 %>" class="style-btn">上一页</a>
            <%}%>
            
            <%if(lastPage < 5){%>
              <a href="#" class="style-btn">已是最后一页</a>
              <%}else{%> 
                <a href="/?num=<%= pageNum+1 %>" class="style-btn">下一页</a>
              <%}%>
          
          </div>
      
      </ul>
      
          

      </div>
    </div>
     
    <div class="mengban">
        <a href="#" class="style-btn del">取消</a>
        <%if(username){%>
          <form  class="formpush">
            
          标题： <input type="text" class="arctxt" name="arctitle"><br/><br/>
          <!-- <textarea cols="30" rows="10" name="content"></textarea> -->
          <div class="arcticleContent">
          <script name="content" id="editor" type="text/plain" style="width:624px;height:450px;"></script>
          </div>
          <input type="button" value="发布文章" class="style-btn pupArc"><br/><br/>
          </form>
    
        <% } %>

    </div>

      <!-- 配置文件 -->
<script type="text/javascript" charset="utf-8" src="/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/ueditor/ueditor.all.min.js">
</script>
<script type="text/javascript" charset="utf-8" src="/ueditor/lang/zh-cn/zh-cn.js">
</script>
<!-- 实例化编辑器 -->
<script type="text/javascript">
  var ue = UE.getEditor('editor');
  $('.pupArc').on('click',function(){
    var arctitle=$('.arctxt').val()
    var content=ue.getContent()
    var data={
      arctitle:arctitle,
      content:content
    }
    $.ajax({
      url:'/users/publish',
      type:'post',
      data:data,
      success:function(res){
        console.log(res)
        location.href='/'
      },
      error:function(err){
        console.log(err)
      }

    })

  })
</script>
<script type="text/javascript">
  $(window).ready(function(){
   $('.wenzhang').on('click',function(){
     console.log(111)
     $('.mengban').css({
       'display':'block'
     })
   })
   $('.mengban .del').on('click',function(){
    $('.mengban').css({
       'display':'none'
     })
   })

   $('.Admintorlogin').on('click',function(){
     console.log(111)
      $.ajax({
        url:'/isAdmin',
        type:'post',
        success:function(res){
          console.log(res)
          if(res.code==1){
            location.href='/adminuser/login'
          }
          else{
            alert('您不是管理员')
          }
        }

      })
   })

  })
</script>


      

    
  </body>
</html>
